function myWordsBind(){
    var wordsTableBody = $(".mywords-my-words-table>tbody");
    $("#myWords-add").click(function(){
        layer.prompt({
            formType: 0,
            value: '',
            title: '添加分词'
        }, function(value, index, elem){
            $.post("/manage/addWords",{text:value},function (data) {
                if(data === "OK"){
                    getMyWords();
                }
            });
            layer.close(index);
        });
    });
    wordsTableBody.delegate(".glyphicon-remove","click",function(data){
        var tr = $(this).parent().parent();
        var LID = tr.data("lid");
        $.post("/manage/deleteWords",{LID:LID},function(data){
            if(data === "OK"){
                tr.remove();
                getFollowWords();
            }
        });
    });
}

function getMyWords(){
    $.post("/manage/getWords",function (json) {
        var res = $.parseJSON(json);
        var total = res.total;
        var words = res.words;
        var wordsTableBody = $(".mywords-my-words-table>tbody");
        wordsTableBody.html("");
        for (i = 0; i < total; i++) {
            followApp = $('<tr><td>'+words[i].lable+'</td><td><span class="glyphicon glyphicon-remove" style="color: red;cursor: pointer"></span></td></tr>');
            followApp.data("lid",words[i].LID);
            wordsTableBody.append(followApp);
        }
    });
}
function init() {
    Aid = 0;
}

$(function(){
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    init();
    myWordsBind()
    getMyWords();
});